import RightMenu from './RightMenu'

window.EcExtension?.ready?.(() => {

    window.ecodeSDK?.overwritePropsFnQueueMapSet?.('WeaRightMenu', {
        fn: (newProps) => {
            newProps.datas = newProps.datas?.filter?.(it => !it.key?.startsWith?.('ecplugin-ecology-chrome-extension-menus_')) ?? []
            try {
                const root = window.EcExtension.Menus.root
                if (root?.children?.length) {
                    newProps.datas.push({
                        key: root?.id,
                        content: (
                            <RightMenu
                                style={{paddingLeft: (newProps.width > 0 ? 30 : 0)}}
                                root={true}
                                title={root?.title}
                                items={root?.children ?? []}
                            />
                        ),
                    })
                }
            } catch (e) {

            }
        },
        order: Number.MAX_VALUE,
    });
})